package com.transformer.shobal.activitys.paint;

import android.content.Context;
import android.graphics.*;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
import com.transformer.shobal.R;

/**
 * Created by tiny on 2015/1/11.
 */
public class MagicTextView extends TextView {
    private int[] colors = new int[4];

    public MagicTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MagicTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        colors[0] = getContext().getResources().getColor(R.color.top);
        colors[1] = Color.GREEN;
        colors[2] = getContext().getResources().getColor(R.color.middle2);
        colors[3] = Color.BLUE;
    }

    public MagicTextView(Context context) {
        super(context);
        colors[0] = getContext().getResources().getColor(R.color.top);
        colors[1] = Color.GREEN;
        colors[2] = getContext().getResources().getColor(R.color.middle2);
        colors[3] = Color.BLUE;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        TextPaint textPaint = this.getPaint();
//        textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
        textPaint.setShader(new LinearGradient(0f,0f,0f,getHeight(),colors,null, Shader.TileMode.CLAMP));
        textPaint.setShadowLayer(2,5,5,getResources().getColor(R.color.live_nickname_shadow));
        super.onDraw(canvas);
    }
}
